package com.day1018.TCP_Socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ServerThread extends Thread {
    private Socket socket;
    public ServerThread(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        InputStream inputStream = null;
        try {
            inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            StringBuffer stringBuffer = new StringBuffer();
            while (inputStream.read(bytes) != -1){
                String str = new String(bytes);
                stringBuffer.append(str);
            }
            System.out.println(this.getName() + ":" + stringBuffer);
            inputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
